package com.waidi.clothespad.common;


import android.content.Context;
import android.util.Log;
import org.ini4j.Config;
import org.ini4j.Ini;
import org.ini4j.Profile.Section;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.Iterator;
import java.util.Properties;
public class DevData
{

    private String server_addr =null;
    private String server_port =null;
    private String dev_id = null;
    private String web_addr = null;
    Context c;

    public  DevData(Context context){c = context;}

    public void setDev_id(String dev_id) {
        this.dev_id = dev_id;
    }
    public void setServer_addr(String server_addr)
    {
        this.server_addr = server_addr;
    }
    public void setServer_port(String server_port)
    {
        this.server_port = server_port;
    }
    public  void setWeb_addr(String web_addr){this.web_addr = web_addr; };



    public String getDev_id(){return dev_id;}
    public String getServer_addr(){return server_addr;}
    public String getServer_port(){return server_port;}
    public String getWeb_addr() {return  web_addr;}

    public void saveDevData()
    {



    }

    public void loadIni()
    {
 /*       File file = new File(c.getFilesDir().getPath().toString() + "/test.ini");

        try {
            if (!file.exists())
            {
                server_addr = "192.168.1.6";
                server_port = "8088";
                dev_id = "4";
                web_addr = "192.168.100.100";

                //file.createNewFile();
                IniFile file1 = new IniFile();
                file1.set("arg","server_addr",server_addr);
                file1.set("arg","server_port",server_port);
                file1.set("arg","dev_id",dev_id);
                file1.set("arg","web_addr",web_addr);
                file1.save(new File(c.getFilesDir().getPath().toString() + "/test.ini"));


            } else
            {
                IniFile file2 = new IniFile(file);
                IniFile.Section ss = file2.get("arg");
                server_addr = file2.get("arg","server_addr").toString();
                server_port = file2.get("arg","server_port").toString();
                dev_id = file2.get("arg","dev_id").toString();
                web_addr = file2.get("arg","web_addr").toString();

                file2.save();
                Log.i("DevData: ", server_addr);
                Log.i("DevData: ", server_port);
                Log.i("DevData: ", dev_id);
                Log.i("DevData: ", web_addr);

            }
        }catch (Exception io) {
            io.printStackTrace();
            Log.e("DevData:",io.getMessage());
        }*/



    }


    public void loadAppConfig()
    {



       /* Properties props = new Properties();
        try {
            File file = new File(c.getFilesDir().getPath().toString() +"/dev.properties");
            Log.i("devdata===:",file.toString());

            if(!file.exists())
            {
                file.createNewFile();
                server_addr = "192.168.1.6";
                server_port="8088";
                dev_id="4";
                web_addr = "192.168.100.100";
                OutputStream output = null;
                output = new FileOutputStream(file);

                props.setProperty("serverAddr",server_addr);
                Log.i("SaveAppConfigsetting:",server_addr);

                props.setProperty("serverPort",server_port);
                Log.i("SaveAppConfigsetting:",server_port);

                props.setProperty("devID",dev_id);
                Log.i("SaveAppConfigsetting:",dev_id);


                props.setProperty("webaddr",web_addr);
                Log.i("SaveAppConfigsetting:",web_addr);
                props.store(output,"users modify" + new Date().toString());
            }
            else
            {
                InputStream in = new FileInputStream(file);
                props.load(in);
                //System.out.println(props.getProperty("serverAddr"));
               // Log.i("DevData: ", props.getProperty("serverAddr"));

                Iterator<String> it=props.stringPropertyNames().iterator();
                while(it.hasNext()) {
                    String key=it.next();
                    String ss = props.getProperty(key);
                    System.out.println(key+":"+props.getProperty(key));
                    if(key.compareTo("devID")==0)
                        dev_id = ss;
                    if(key.compareTo("serverPort")==0)
                        server_port = ss;
                    if(key.compareTo("serverAddr")==0)
                        server_addr = ss;
                    if(key.compareTo("webaddr")==0)
                        web_addr = ss;

                }

                Log.i("DevData: ",server_addr);
                Log.i("DevData: ",server_port);
                Log.i("DevData: ",dev_id);
                Log.i("DevData: ",web_addr);

                in.close();
*/

/*
                OutputStream output = null;
                File file2 = new File(c.getFilesDir().getPath().toString() +"/dev.properties");
                Log.i("SETTTTTTT:",file2.toString());
                output = new FileOutputStream(file2);
                props.setProperty("serverAddr","192.168.3.4");

                props.store(output,"users modify" + new Date().toString());
                output.close();
*/









/*            }

        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            Log.e("DevData:",e1.getMessage());
        }*/
    }




}




